﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsTestUtilities.RowTests;
using MsTestUtilities;

namespace MsTestUtilitiesTests.RowTests.TestScenarioBuilderTests
{
    [TestClass]
    public class StandardAssertTests
    {
        [TestMethod]
        public void EqualityExpectationFails()
        {
            ExAssert.Throws<AssertFailedException>(() => Test(1, 2, Identity));
        }

        [TestMethod]
        public void EqualityExpectationPasses()
        {
            Test(1, 1, Identity);
        }

        [TestMethod]
        public void MethodUnderTestThrowsException()
        {
            ExAssert.Throws<AssertFailedException>(() => 
                Test(1, 1, i => { throw new InvalidOperationException(); }));
        }

        private int Identity(int i)
        {
            return i;
        }

        private void Test(int given, int expected, Func<int, int> methodUnderTest)
        {
            new TestScenarioBuilder<int, int>()
                .For(methodUnderTest)
                .Given(given).Do(g => Assert.AreEqual(g, expected)).Fact
                .Evaluate();
        }
    }
}
